#include <iostream>
#include <vector>
using namespace std;
int n = 0, m = 0, len = 1, resLen = 0;
vector<int> path;
bool vis[101][101];
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
 
void dfs(vector<vector<int>>& arr, int sr, int sc)
{
    resLen = max(len, resLen);
    for(int i = 0; i < 4; ++i)
    {
        int x = sr + dx[i], y = sc + dy[i];
        if(x >= 0 && x < n && y >= 0 && y < m
            && !vis[x][y] && arr[x][y] > arr[sr][sc])
        {
            path.push_back(arr[x][y]);
            ++len;
            dfs(arr, x, y);
            path.pop_back();
            --len;
        }
    }
}
 
int main()
{
    cin >> n >> m;
    vector<vector<int>> arr(n, vector<int>(m));
    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < m; ++j)
        {
            cin >> arr[i][j];
        }
    }
    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < m; ++j)
        {
            dfs(arr, i, j);
        }
    }
    cout << resLen << endl;
    return 0;
}